//
//  JMReleaseStrVController.m
//  jiMuOperate
//
//  Created by 翁仪 on 16/5/5.
//  Copyright © 2016年 jinXinFengLi. All rights reserved.
//

#import "JMReleaseStrVController.h"
#import "JMOperate.pch"
#import "bayTimeTVCell.h"
#import "SellTimeTVCell.h"
#import "buyConditionCell.h"
#import "sellConditionCell.h"
#import "footerCell.h"
@interface JMReleaseStrVController ()<UITableViewDataSource,UITableViewDelegate>

@end

@implementation JMReleaseStrVController

- (void)viewDidLoad {
    [super viewDidLoad];
    [[self navigationController] setNavigationBarHidden:NO animated:YES];

    // Do any additional setup after loading the view.
   self.navigationItem.title = @"发布策略";
    [self addTabelView];

}
-(void)addTabelView{
    
    UITableView *relStrTView =[[UITableView alloc] initWithFrame: CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) style:UITableViewStyleGrouped];
    relStrTView.delegate = self;
    
    relStrTView.dataSource = self;
    
    relStrTView.editing = YES;
    
    [self.view addSubview:relStrTView];
    
    
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 8;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
#warning Incomplete implementation, return the number of rows
    if (section==0) {
        return 3;
    }
    if (section==1) {
        return 4;
    }
    if (section==2) {
        return 1;
    }
    if (section==3) {
        return 1;
    }
    if (section==4) {
        return 2;
    }
    if (section==5) {
        return 1;
    }
    if (section==6) {
        return 1;
    }
    if (section==7) {
        return 1;
    }

    return 0;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    //创建cell
    static NSString *ID = @"cell";

//    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    if (cell==nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        
        
        UILabel *label  = [[UILabel alloc] init];
        [label setFont:[UIFont systemFontOfSize: 14]];
        [cell.contentView addSubview:label];
        CGFloat padingW=15;
        if (indexPath.section ==0&&indexPath.row==0) {
        
            label.frame = CGRectMake(padingW, 0, SCREEN_WIDTH-padingW, 44);
            label.text =@"您当前所在等级最多能发布预期收益不超过2%的策略,并且自己需要绑定支持1-10个红松果";
            [label setFont:[UIFont systemFontOfSize: 12]];
            label.textColor = RGB(169, 169, 169);
            label.lineBreakMode = NSLineBreakByWordWrapping;
            label.numberOfLines = 0;
        }
        if (indexPath.section ==0&&indexPath.row==1) {
            label.frame = CGRectMake(padingW, 0, SCREEN_WIDTH-padingW, 44);
            label.text =[NSString stringWithFormat:@"可用红松果数 : %ld 个",(long)_pinealNum];
        }
        if (indexPath.section ==0&&indexPath.row==2) {
            label.frame = CGRectMake(padingW, 0, 130, 44);
            label.text =[NSString stringWithFormat:@"跟投红松果个数"];
            CGFloat throwTFX = label.frame.origin.x+label.frame.size.width;
            CGFloat throwTFH = 30;
            CGFloat throwTFY = (44-throwTFH)*0.5;
            CGFloat throwTFW = SCREEN_WIDTH-throwTFX - padingW;

            UITextField *throwTF=[self createTextFieldWithFrame:CGRectMake(throwTFX, throwTFY, throwTFW, throwTFH) Placeholder:@"请输入跟投个数"];
            _throwNum =[throwTF.text intValue];
            [cell.contentView addSubview:throwTF];
        }
        if (indexPath.section ==1&&indexPath.row==0) {
            label.frame = CGRectMake(padingW, 0, 130, 44);
            label.text =[NSString stringWithFormat:@"证券简称:"];
            
            CGFloat throwTFX = label.frame.origin.x+label.frame.size.width;
            CGFloat throwTFH = 30;
            CGFloat throwTFY = (44-throwTFH)*0.5;
            CGFloat throwTFW = SCREEN_WIDTH-throwTFX - padingW;
            UITextField *throwTF=[self createTextFieldWithFrame:CGRectMake(throwTFX, throwTFY, throwTFW, throwTFH) Placeholder:@"请输入证券简称"];
             _stockName =throwTF.text;
            [cell.contentView addSubview:throwTF];
        }
        if (indexPath.section ==1&&indexPath.row==1) {
            label.frame = CGRectMake(padingW, 0, 130, 44);
            label.text =[NSString stringWithFormat:@"证券代码:"];
            
            CGFloat throwTFX = label.frame.origin.x+label.frame.size.width;
            CGFloat throwTFH = 30;
            CGFloat throwTFY = (44-throwTFH)*0.5;
            CGFloat throwTFW = SCREEN_WIDTH-throwTFX - padingW;
            
            UITextField *throwTF=[self createTextFieldWithFrame:CGRectMake(throwTFX, throwTFY, throwTFW, throwTFH) Placeholder:@"请输入证券代码"];
             _stockNum =[throwTF.text intValue];
            [cell.contentView addSubview:throwTF];
        }
        if (indexPath.section ==1&&indexPath.row==2) {
            label.frame = CGRectMake(padingW, 0, 140, 44);
            label.text =[NSString stringWithFormat:@"拟买入价格区间上限："];
            
            CGFloat throwTFX = label.frame.origin.x+label.frame.size.width;
            CGFloat throwTFH = 30;
            CGFloat throwTFY = (44-throwTFH)*0.5;
            CGFloat throwTFW = SCREEN_WIDTH-throwTFX - padingW;
            UITextField *throwTF=[self createTextFieldWithFrame:CGRectMake(throwTFX, throwTFY, throwTFW, throwTFH) Placeholder:@"请输入上限"];
            _bMaxValue =[throwTF.text intValue];

            [cell.contentView addSubview:throwTF];
        }
        if (indexPath.section ==1&&indexPath.row==3) {
            label.frame = CGRectMake(padingW, 0, 140, 44);
            label.text =[NSString stringWithFormat:@"拟买入价格区间下限："];
            
            CGFloat throwTFX = label.frame.origin.x+label.frame.size.width;
            CGFloat throwTFH = 30;
            CGFloat throwTFY = (44-throwTFH)*0.5;
            CGFloat throwTFW = SCREEN_WIDTH-throwTFX - padingW;
            UITextField *throwTF=[self createTextFieldWithFrame:CGRectMake(throwTFX, throwTFY, throwTFW, throwTFH) Placeholder:@"自动根据上限＊0.98"];
            _bMinValue = _bMaxValue*0.98;
            [cell.contentView addSubview:throwTF];
        }
        
        if (indexPath.section ==4&&indexPath.row==0) {
            
            label.frame = CGRectMake(padingW, 0, 140, 44);
            label.text =[NSString stringWithFormat:@"拟卖出价格区间上限："];
            
            CGFloat throwTFX = label.frame.origin.x+label.frame.size.width;
            CGFloat throwTFH = 30;
            CGFloat throwTFY = (44-throwTFH)*0.5;
            CGFloat throwTFW = SCREEN_WIDTH-throwTFX - padingW;
            UITextField *throwTF=[self createTextFieldWithFrame:CGRectMake(throwTFX, throwTFY, throwTFW, throwTFH) Placeholder:@"请输入下限"];
            _sMaxValue = _sMinValue*1.02;
            [cell.contentView addSubview:throwTF];
        }
        if (indexPath.section ==4&&indexPath.row==1) {
            label.frame = CGRectMake(padingW, 0, 140, 44);
            label.text =[NSString stringWithFormat:@"拟买入价格区间下限："];
            
            CGFloat throwTFX = label.frame.origin.x+label.frame.size.width;
            CGFloat throwTFH = 30;
            CGFloat throwTFY = (44-throwTFH)*0.5;
            CGFloat throwTFW = SCREEN_WIDTH-throwTFX - padingW;
            UITextField *throwTF=[self createTextFieldWithFrame:CGRectMake(throwTFX, throwTFY, throwTFW, throwTFH) Placeholder:@"自动根据下限＊1.02"];
            _bMinValue = _bMaxValue*0.98;
            [cell.contentView addSubview:throwTF];
        }

        if (indexPath.section ==2&&indexPath.row==0) {
            bayTimeTVCell *cell =[[bayTimeTVCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
            return cell;
        }
        if (indexPath.section ==3&&indexPath.row==0) {
            buyConditionCell *cell =[[buyConditionCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
            return cell;
        }

        if (indexPath.section ==5&&indexPath.row==0) {
            SellTimeTVCell *cell =[[SellTimeTVCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
            return cell;
        }
        if (indexPath.section ==6&&indexPath.row==0) {
            sellConditionCell *cell =[[sellConditionCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
            return cell;
        }
        if (indexPath.section ==7&&indexPath.row==0) {
            footerCell *cell =[[footerCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
            return cell;
        }



    }
        return cell;
   
}
-(UITextField *)createTextFieldWithFrame:(CGRect)frame Placeholder:(NSString*)placeHolder {

    UITextField *textField=[ARC createTextFieldWithFrame:frame Font:12 Placeholder:placeHolder SecureTextEntry:NO];
    textField.textAlignment = NSTextAlignmentLeft;
return textField;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 10;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{

    return 0.01;

}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return NO;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section ==2) {
        return 100;
    }
    if (indexPath.section ==5) {
        return 100;
    }
    if (indexPath.section ==3) {
        return 70;
    }
    if (indexPath.section ==6) {
        return 70;
    }
    if (indexPath.section ==7) {
        return 200;
    }


    return 44;
}
@end
